home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / thenet / x1j4_src / crun.mac < prev    next >
Encoding:
Text File  |  1995-01-20  |  11.0 KB  |  332 lines

  1. ; ***********************************************************************
  2. ; *                                                                     *
  3. ; *                                                                     *
  4. ; *    *****                      *****                                 *
  5. ; *      *****                  *****                                   *
  6. ; *        *****              *****                                     *
  7. ; *          *****          *****                                       *
  8. ; *            *****      *****                                         *
  9. ; *              *****  *****                                           *
  10. ; *            *****      *****                                         *
  11. ; *          *****          *****          The Firmware. The Net.       *
  12. ; *        *****              *****        Portable. Compatible.        *
  13. ; *      *****                  *****      Public Domain.               *
  14. ; *    *****                      *****    By NORD><LINK.               *
  15. ; *                                                                     *
  16. ; *                                                                     *
  17. ; *                                                                     *
  18. ; *    CRUNTIME.MAC   -     Z80 C Runtime Library                       *
  19. ; *                         (modifizierte Version des Runtime-Moduls    *
  20. ; *                         aus dem Q/C-Compilerpaket)                  *
  21. ; *                                                                     *
  22. ; *                                                                     *
  23. ; *    angelegt:      DC4OX                                             *
  24. ; *    modifiziert:                                                     *
  25. ; *                                                                     *
  26. ; ***********************************************************************
  27.  
  28. ; G8KBB April 1991
  29. ; This is a much reduced version for an alternative compiler.
  30. ; It misses out most of the runtime functions.
  31. ; ALso, function entry/exit changed to preserve IX
  32.  
  33. ; released as thenet x-1j september 1993
  34.  
  35.     .z80
  36.  
  37.  
  38. ; +---------------------------------------------------------------------+
  39. ; |                                                                     |
  40. ; | Funktionsstart fuer Parameter, es werden die Stackframepointer      |
  41. ; | (BC/IX) gesetzt, so dass auf Funktionsargumente zugegriffen werden  |
  42. ; | kann.                                                               |
  43. ; |                                                                     |
  44. ; | Return :  HL  -  benutzt                                            |
  45. ; |                                                                     |
  46. ; +---------------------------------------------------------------------+
  47.  
  48.           public fentp
  49.           public ?en
  50.  
  51. fentp:
  52. ?en:      pop   HL              ; Returnadresse holen
  53.           push    IX        ; save IX ( G8KBB )
  54.           push  BC              ; Stackframe-Pointer sichern
  55.           ld    IX,0            ; lokaler Stackframe-Pointer, kein Platz
  56.           add   IX,SP           ; fuer lokale Variablen benoetigt
  57.           push  IX              ; BC auch Stackframe-Pointer
  58.           pop   BC
  59.           jp    (HL)            ; das war's - weiter an Returnadresse
  60.  
  61.  
  62.  
  63.  
  64.  
  65. ; +---------------------------------------------------------------------+
  66. ; |                                                                     |
  67. ; | Funktionsstart fuer Parameter/Locals, wie fentp, zusaetzlich wird   |
  68. ; | Platz fuer lokale Variable auf dem Stack geschaffen, Platz in Bytes |
  69. ; | negativ als Parameter hinter Aufruf (16 Bit).                       |
  70. ; |                                                                     |
  71. ; | Return :  SP      -  um angeforderten Platz korrigiert              |
  72. ; |           BC, IX  -  neuer Stackframe-Pointer                       |
  73. ; |           DE, HL  -  benutzt                                        |
  74. ; |                                                                     |
  75. ; |                                                                     |
  76. ; +---------------------------------------------------------------------+
  77.  
  78.           public fentpl
  79.           public ?ens
  80.  
  81. fentpl:
  82. ?ens:     pop   HL              ; Adresse Aufrufpar. (angeforderter Platz)
  83.           push    IX        ; save IX ( G8KBB )
  84.           push  BC              ; Stackframe-Pointer sichern
  85.           ld    E,(HL)          ; LSB angeforderter Platz 
  86.           inc   HL              ; Zeiger auf MSB angeforderter Platz
  87.           ld    D,(HL)          ; MSB angeforderter Platz
  88.           inc   HL              ; neue Returnadresse hinter Parameter
  89.           ex    DE,HL           ; Returnadresse <-> angeforderter Platz
  90.           add   HL,SP           ; Stack um angeforderten Platz vermindern
  91.           ld    SP,HL           ; und den Platz reservieren
  92.           ld    B,H             ; lokalen Stackframe-Pointer setzen
  93.           ld    C,L
  94.           push  BC              ; auch in IX
  95.           pop   IX
  96.           ex    DE,HL           ; HL = Returnadresse
  97.           jp    (HL)            ; das war's - dort weitermachen
  98.  
  99.  
  100.  
  101.  
  102.  
  103. ; +---------------------------------------------------------------------+
  104. ; |                                                                     |
  105. ; | Funktionsausgang fuer Parameter/Locals, nach fentpl, der lokal      |
  106. ; | benoetigte Platz wird zurueckgegeben, Platz in Bytes positiv als    |
  107. ; | Parameter hinter Aufruf (16 Bit).                                   |
  108. ; |                                                                     |
  109. ; | Return :  SP      -  um zurueckzugebenden Platz korrigiert          |
  110. ; |           BC, IX  -  alter Stackframe-Pointer (aufrufende Funktion) |
  111. ; |           HL      -  bleibt (Returnwert der Funktion)               |
  112. ; |           A, DE   -  benutzt                                        |
  113. ; |                                                                     |
  114. ; +---------------------------------------------------------------------+
  115.  
  116.           public fextpl
  117.           public ?exs
  118.  
  119. fextpl:
  120. ?exs:     ex    DE,HL           ; Returnwert der Funktion sichern
  121.           pop   HL              ; Adresse Aufrufparam. (zurueckzugeb. Platz)
  122.           ld    A,(HL)          ; LSB des zurueckzugebenden Platzes holen
  123.           inc   HL              ; Zeiger auf MSB
  124.           ld    H,(HL)          ; MSB holen 
  125.           ld    L,A             ; HL = 16-Bit Anzahl Bytes zureckzugeben
  126.           add   HL,SP           ; = Anzahl Bytes Stack zu korrigieren
  127.           ld    SP,HL           ; lokalen Platz deallokieren
  128.           ex    DE,HL           ; restaurieren des Returnwertes der Funktion
  129.           pop   BC              ; Stackframe-Pointer restaurieren
  130.           pop   IX              ; sowie Indexregister (auch Stackframe-P.)
  131.           ret                   ; das war's
  132.  
  133.  
  134.     public ?inc
  135.     public ?sxt
  136.     public ?gf
  137.     public ?g
  138.     public ?sn
  139.     public ?addhl
  140.     public ?loc
  141. ?inc:
  142. ?sxt:
  143. ?gf:
  144. ?g:
  145. ?sn:
  146. ?addhl:
  147. ?loc:    ret
  148.  
  149. ;-----------------------------------------------------------------------
  150. ;        SUPPORT.MAC
  151. ;-----------------------------------------------------------------------
  152. ;
  153. ;    Z80 run time library
  154. ;    DWP  January 1995
  155. ;
  156. ;    Modified DAR Jan 1995
  157. ;    and routines in RST locations commented out
  158. ;
  159. ;    Routines return TRUE or FALSE
  160. ;
  161. ;    TRUE    HL=1,  Z flag clear ( NZ )
  162. ;    FALSE    HL=0   Z flag set
  163.  
  164.     .Z80
  165.     public .nt
  166. ;-----------------------------------------------------------------------
  167. ; .nt    ! (NOT) operator
  168. ;    if( HL == 0 )
  169. ;        return TRUE
  170. ;    else
  171. ;        return FALSE
  172.  
  173. .nt:    ld    a,h
  174.     or    l
  175.     jr    z,.true
  176.     jr    .false
  177.  
  178. ;    public .eq,.ne
  179. ;-----------------------------------------------------------------------
  180. ; .eq .ne  if( HL == DE ) or ( HL != DE )
  181. ;         return TRUE
  182. ;    else
  183. ;        return FALSE
  184.  
  185. ;.eq:    xor   a        ; Clear carry
  186. ;    sbc   hl,de
  187. ;    jr    z,.true
  188. .false: xor   a        ; Clear carry (and A)
  189.     ld    h,a    ; Set HL = 0;
  190.     ld    l,a
  191.     ret
  192.  
  193. ;.ne:    xor   a        ; Clear carry
  194. ;    sbc   hl,de    ; Compare
  195. ;    jr    z,.false
  196. .true:    ld    hl,1    
  197.     ld    a,l
  198.     or    h
  199.     ret
  200.  
  201.     public .le,.ge
  202. ;-----------------------------------------------------------------------
  203. ; .le .ge
  204. ;    if( DE <= HL )  (DE >= HL )
  205. ;        return TRUE
  206. ;    else
  207. ;        return FALSE
  208.  
  209. .ge:    ex    de,hl    ; swap registers
  210. .le:    ld    a,h    ; Compare signs
  211.     xor   d
  212.     jp    m,.sdiff    ; Skip if their different
  213.     xor   a        ; They're the same, Clear carry
  214.     sbc   hl,de    ; Compare them
  215.     jr    nc,.true    ; TRUE if HL < DE
  216.     jr    .false    ; else FALSE
  217. .gdiff:
  218.     ex    de,hl
  219. .sdiff:
  220.     ld    a,d    ; Get sign of DE
  221.     rlca        ; ..to LSB
  222.     and   1        ; Mask off
  223.     ld    l,a    ; Set in HL and return
  224.     ld    h,0
  225.     ret
  226.  
  227.     public .lt,.gt
  228. ;-----------------------------------------------------------------------
  229. ; .lt .gt
  230. ;    if( DE < HL )  (DE > HL )
  231. ;        return TRUE
  232. ;    else
  233. ;        return FALSE
  234.  
  235. .lt:    ex    de,hl    ; Swap values
  236. .gt:    ld    a,h    ; Compare signs
  237.     xor   d
  238.     jp    m,.gdiff    ; Skip if their different
  239.     xor   a        ; They're the same, Clear carry
  240.     sbc   hl,de    ; Compare them
  241.     jr    c,.true    ; TRUE if HL < DE
  242.     jr    .false    ; else FALSE
  243.  
  244.     public .ng
  245. ;-----------------------------------------------------------------------
  246. ; .ng    Negate HL
  247.  
  248. .ng:    ld    a,l
  249.     cpl
  250.     ld    l,a
  251.     ld    a,h
  252.     cpl
  253.     ld    h,a
  254.     inc   hl
  255.     ld    a,h
  256.     or    l
  257.     ret
  258.  
  259. ;    public .sb
  260. ;-----------------------------------------------------------------------
  261. ; .sb
  262. ;    return( DE-HL )
  263.  
  264. ;.sb:    ex    de,hl
  265. ;    or    a
  266. ;    sbc   hl,de
  267. ;    ret
  268.  
  269.     public .swt
  270. ;-----------------------------------------------------------------------
  271. ; .swt
  272. ;    Switch table execution
  273. ;    ld   hl,<key>
  274. ;    call .swt
  275. ;    defw  <# entries>
  276. ;    defw  <match>,<address>
  277. ;    defw  <match>,<address>
  278. ;    ....
  279. ;    defw  <match>,<address>
  280. ;    defw  <address>        (default value)
  281.    
  282. .swt:    ex    de,hl    ; Comparison value in DE
  283.     pop   hl    ; address pointer to HL
  284.     push  bc    ; Save BC
  285.     ld    c,(hl)    ; BC = # entries in table
  286.     inc   hl
  287.     ld    b,(hl)
  288.     inc   bc    ; Bump count by one
  289.     dec   hl
  290. swt.1:    inc   hl    ; Point to table entry
  291.     inc   hl
  292.     ld    a,e    ; Value to check for
  293.     cpi        ; Test ( Z on match, PO if BC=0)
  294.     jp    po,swt.def
  295.     jr    nz,swt.2    ; Skip if no match
  296.     ld    a,b    ; ..else check hi byte
  297.     cp    (hl)
  298. swt.2:    inc   hl    ; HL->address
  299.     jr    nz,swt.1    ; repeat if no match
  300.     inc   hl    ; Matched on 2nd compare
  301. swt.def:
  302.     ld    a,(hl)    ; Pick up address
  303.     dec   hl
  304.     ld    l,(hl)
  305.     ld    h,a
  306.     pop   bc    ; reset BC
  307.     jp    (hl)    ; Go to it
  308.  
  309.     public .ue,.uf
  310. ;-----------------------------------------------------------------------
  311. ; .ue (unsigned <=)  .uf (unsigned >=)
  312. .uf:    ex    de,hl    ; uge
  313. .ue:    xor   a        ; Clear carry
  314.     sbc   hl,de    ; Compare
  315.     jr    nc,.true    ; TRUE if HL < DE
  316.     jr    .false    ; else FALSE
  317.  
  318.     public .ul    ;,.ug
  319. ;-----------------------------------------------------------------------
  320. ; .ul (unsigned < )  .ug (unsigned > )
  321.  
  322. .ul:    ex    de,hl
  323.     xor   a
  324. ;.ug:    xor   a        ; Clear Carry
  325.     sbc   hl,de
  326.     jr    c,.true
  327.     jr    .false
  328.  
  329.           public end_
  330. end_:
  331.           end
  332.